package cn.gson.oasys.model.dao.user;

import cn.gson.oasys.model.entity.user.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface UserDao extends JpaRepository<User, Long>{
    
	List<User>  findByUserId(Long id);

//	//根据用户名模糊查找
//	@Query("update User ta set ta.password=:password where ta.userId=:id")
//	@Modifying
//	int updateByid(@Param("id")Long id,@Param("password")String password);


	@Query("select u from User u where u.userName=:name")
    User findid(@Param("name") String name);

	//根据名字找用户
	User findByUserName(String title);

	//根据用户名模糊查找
	@Query("from User u where u.userName like %:name% or u.realName like %:name%")
	Page<User> findbyUserNameLike(@Param("name") String name, Pageable pa);

	//根据真实姓名模糊查找
	Page<User> findByrealNameLike(String title, Pageable pa);

	/**
	 * 用户管理查询可用用户
	 * @param isLock
	 * @param pa
	 * @return
	 */
	Page<User> findByIsLock(Integer isLock, Pageable pa);


//	@Query("select u from User u where u.role.roleId=?1")
//	List<User> findrole(Long lid);

	/*通过（用户名或者电话号码）+密码查找用户*/
	@Query("from User u where (u.userName = ?1 or u.userTel = ?1) and u.password =?2")
    User findOneUser(String userName, String password);

	@Query("from User u where (u.userName = ?1 or u.userTel = ?1)")
    User findOneUser(String userName);

}
